package br.net.woodstock.tickettoride.orm;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import br.net.woodstock.rockframework.persistence.validator.jee.Reference;

@Entity
@Table(name = "ttr_application_permission")
public class ApplicationPermission extends AbstractIntegerEntity {

	private static final long	serialVersionUID	= 4439831409621495497L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "application_permission_id", unique = true)
	private Integer				id;

	@Column(name = "application_permission_comment", length = 100, nullable = false)
	@Size(min = 1, max = 100)
	@NotNull
	private String				comment;

	@Column(name = "application_permission_date", nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	@NotNull
	private Date				date;

	@ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "dest_application_id", referencedColumnName = "application_id", nullable = false)
	@NotNull
	@Reference
	private Application			destination;

	@ManyToOne(optional = false, fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "src_application_id", referencedColumnName = "application_id", nullable = false)
	@NotNull
	@Reference
	private Application			source;

	public ApplicationPermission() {
		super();
	}

	public ApplicationPermission(final Integer id) {
		super();
		this.id = id;
	}

	@Override
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final Integer id) {
		this.id = id;
	}

	public String getComment() {
		return this.comment;
	}

	public void setComment(final String comment) {
		this.comment = comment;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(final Date date) {
		this.date = date;
	}

	public Application getDestination() {
		return this.destination;
	}

	public void setDestination(final Application destination) {
		this.destination = destination;
	}

	public Application getSource() {
		return this.source;
	}

	public void setSource(final Application source) {
		this.source = source;
	}

}
